package com.captainbank.tcl.tclapplication.ui.activity.function;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.animation.BounceInterpolator;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.TextView;

import com.captainbank.tcl.tclapplication.R;
import com.captainbank.tcl.tclapplication.ui.activity.basic.BaseActivity;
import com.github.florent37.viewanimator.AnimationListener;
import com.github.florent37.viewanimator.ViewAnimator;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by TCL on 2019/8/14.
 * Describe:
 */
public class ViewAnimatorActivity extends BaseActivity {
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.iv)
    ImageView iv;
    @BindView(R.id.tv)
    TextView tv;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_view_animator;
    }

    @Override
    protected void initView() {
        toolbar.setTitle(getString(R.string.title_viewanimator));
    }

    @OnClick({R.id.btn1, R.id.btn2, R.id.btn3, R.id.btn4,
            R.id.btn5, R.id.btn6, R.id.btn7, R.id.btn8, R.id.btn9})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn1:
                ViewAnimator
                        .animate(iv).translationY(-1000, 0).alpha(0, 1)
                        .andAnimate(tv).dp().translationX(-20, 0).decelerate().duration(2000)
                        .thenAnimate(iv).scale(1f, 0.5f, 1f).accelerate().duration(1000)
                        .start();
                break;
            case R.id.btn2:
                ViewAnimator
                        .animate(iv, tv).scale(0, 1)
                        .thenAnimate(iv).dp().translationY(-200, 0)
                        .thenAnimate(tv).dp().translationY(200, 0)
                        .thenAnimate(iv, tv).flash()
                        .start();

                break;
            case R.id.btn3:
                ViewAnimator
                        .animate(iv).waitForHeight().dp().width(100, 200).dp().height(50, 100)
                        .thenAnimate(tv).textColor(Color.BLACK, Color.GREEN).backgroundColor(Color.WHITE, Color.BLACK)
                        .start();
                break;
            case R.id.btn4:
                ViewAnimator
                        .animate(iv).rotation(360)
                        .thenAnimate(tv).custom(new AnimationListener.Update<TextView>() {
                    @Override
                    public void update(TextView view, float value) {
                        view.setText(String.format("%.02f",value));
                    }
                }, 0, 1)
                        .start();
                break;
            case R.id.btn5:
                ViewAnimator
                        .animate(iv).shake().interpolator(new LinearInterpolator())
                        .andAnimate(tv).bounceIn().interpolator(new BounceInterpolator())
                        .start();
                break;
            case R.id.btn6:
                ViewAnimator
                        .animate(iv).flash().repeatCount(4)
                        .andAnimate(tv).flipHorizontal()
                        .start();
                break;
            case R.id.btn7:
                ViewAnimator
                        .animate(iv).wave().duration(5000)
                        .andAnimate(tv).tada()
                        .start();
                break;
            case R.id.btn8:
                ViewAnimator
                        .animate(iv).pulse()
                        .andAnimate(tv).standUp()
                        .start();
                break;

            case R.id.btn9:
                ViewAnimator
                        .animate(iv).swing()
                        .andAnimate(tv).wobble()
                        .start();
                break;
        }
    }
}
